<?php
//Requires connectDB and getResourceIDsByContainer
require("dbFunctions.php");

/** 
 * Given a valid QR Code, get all the details about all of
 * the resources within the container, if the provided QR
 * Code is a container.
 * The functionality for returning details for a list of
 * QR Codes as JSON is already done through the script
 * called resourceDetails.php. This file is adds a little
 * abstraction and allows the android device to specify
 * the top-level container and get back all of the data
 * for that resource and all resources it contains.
 * 
 * Author: Steve Gennaoui
 * Date: 11/21/2012
 */

$original_qr_code = $_REQUEST['qr_code'];

if( is_null($original_qr_code) || !isset($original_qr_code) )
	die("Provided QR Code was not provided.");
if( !is_numeric($original_qr_code) )
	die("Provided QR Code was non-numeric.");

//Get all the IDs that are part of this container
$contained_ids = getResourceIDsInContainer($original_qr_code);
//Encode these IDs as json
$json_encoded_data = json_encode( $contained_ids );
//Package them up as POST parameters for resourceDetails script.
$data = array('qr_code' => $json_encoded_data);

//Initialize the cURL to go to the resourceDetails.php page
$ch = curl_init("127.0.0.1/db_manage/resourceDetails.php");
//Set cURL options: Send POST data
curl_setopt($ch, CURLOPT_POST, 1);
//Set cURL options: Specify the POST field-> value combos
// (resourceDetails.php?qr_code=[json_encoded_qr_codes] as POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//Set cURL options: Specify that all output from call will be returned
// by the execute method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Execute the web page with post parameters and
// put results into $return
$return = curl_exec($ch);
//Close the cURL conncetion
curl_close($ch);

//Print the result of the resourceDetails script
// already json_encoded
print_r($return);
?>
